package trab4;

import java.awt.*;

import sim.core.* ;


public class Main extends Simulation implements Displayable {
	
	public static final int TOTAL_CLIENTS = 9 ;
	public static final int TOTAL_SERVERS = 4; // usar quadrados perfeitos... 1, 4, 9, 16, 25, etc.
	
	public static final boolean DEBUG = true;

	Main() {
		super() ;
	}

	Main init() {
		Gui.addItem( this) ;
		Gui.removeItem( Network ) ;
		
		for( int i = 0 ; i < TOTAL_SERVERS ; i++ )
			new Server() ;
		
		for( int i = 0 ; i < TOTAL_CLIENTS ; i++ )
			new Client();
		
		//Initialize the simulation nodes (includes servers and clients)
		for( Node i : NodeDB.nodes ) 
			i.init() ;
		
		
		new Task(100) {
			public void run() {
				ServerDB.randomServer().crash() ;
				reSchedule( 10 + 5000 * rg.nextDouble() ) ;
			}
		} ;
		super.setSimulationMaxTimeWarp( 25 ) ;
		System.out.println("Init complete...") ;
		return this ;
	}
	

	public static void main( String[] args ) throws Exception {
		new Main().init().start() ;
	}

	public void display(Graphics2D gu, Graphics2D gs) {
		for( Node i : NodeDB.nodes )
			i.display( gu, gs) ;		
	}
	
}
